package org.cytoscape.myapp.cytoscape_app_v1.internal.visual;

import org.cytoscape.myapp.cytoscape_app_v1.internal.helpers.ModelUtils;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.view.vizmap.VisualMappingFunction;
import org.cytoscape.view.vizmap.mappings.DiscreteMapping;

public class MappingFunctionDiscreteSimple implements MappingFunction{
	
	private String nameAttribute;
	private VisualInstanceDependecies dependecies;
	private VisualProperty<?> property;
	private Class<?> type;
	
	

	public String getNameAttribute() {
		return nameAttribute;
	}

	public void setNameAttribute(String nameAttribute) {
		this.nameAttribute = nameAttribute;
	}

	public MappingFunctionDiscreteSimple( String nameAttribute, VisualInstanceDependecies dependecies,
												  VisualProperty<?> property,
												  Class<?> type){
		this.nameAttribute = nameAttribute;
		this.dependecies = dependecies;
		this.property = property;
		this.type = type;
	}
	
	@Override
	public <T> VisualMappingFunction<?, ?> createVisualMappingFunction() {
		
		@SuppressWarnings("unchecked")
		DiscreteMapping<Double, Double> mapping = (DiscreteMapping<Double, Double>)
				dependecies.getVmfFactoryD().createVisualMappingFunction(this.nameAttribute, this.type, this.property);
		
		mapping.putAll(ModelUtils.getDiscreteMapping(dependecies.getApplicationManager().getCurrentNetwork(),this.nameAttribute));
		
		return mapping;
	}

}
